#include <header.h>

int getnum(char *file_fd){
    int num = 0;
    DIR *p = opendir(file_fd);

    while(1){
        struct dirent * pdirent = readdir(p);
        if(pdirent == NULL){
            return num;
        }
        if((pdirent->d_type == DT_DIR) && (strcmp(pdirent->d_name,".") != 0) && (strcmp(pdirent->d_name,"..") != 0)){

            num ++;
            char buf1[300] = {0};
            sprintf(buf1,"%s/%s",file_fd,pdirent->d_name);
            int size = getnum(buf1);
            num += size;
        }
    }
    return num;
}

int main(){
    //int file_fd = open("test",O_RDWR);
    //int ret = getnum((char *)file_fd);//file_fd本质还是文件描述符，给他强转成字符串，内容依旧没有变化

    int ret = getnum("./test");
    printf("ret : %d\n",ret);
    return 0;
}

